package com.loveprogrammer.eternity.skill.support.skills;

import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.skill.support.states.BurnState;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0
 * @description: 灼烧，单体伤害
 * @author: eric
 * @date: 2022-08-16 16:53
 **/
public class BurnSkill extends AbstractSkill {

    public BurnSkill(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    protected Tuple<String, List<Character>> skillLaunch(Character character,
                                                         List<? extends Character> attack,
                                                         List<? extends Character> defences) {
        Tuple<String, List<Character>> result = new Tuple<>();
        Character defence = findSingleAttacker(defences, true);
        StringBuilder builder = new StringBuilder();
        // 每秒掉落10点生命，持续10秒
        BurnState burnState = new BurnState(defence, defences, getHarm(character));
        boolean state = defence.acquireState(burnState, 5);
        // 施展成功 启动一个定时器，5秒钟
        if (state) {
            builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                    .append(character.getHpMax()).append(")").append(" 使用技能[")
                    .append(getName()).append(" ").append(getLevel()).append("级】攻击了 ").append(defence.getName());
            setTimeTask(burnState, 5);
            builder.append(defence.getName()).append("进入灼烧状态;\n");
        } else {
            builder.append(defence.getName()).append("灼烧无效;\n");
        }
        List<Character> value = new ArrayList<>();
        value.add(defence);
        result.setValue(value);
        result.setKey(builder.toString());
        return result;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) ((getBaseHarm() + (character.getTechnique() * 0.2)) * (1 + (getLevel() + 3) / 3));
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }

    @Override
    public boolean check(Character character) {
        if (restInterval() <= 0) {
            return true;
        }
        return false;
    }

    @Override
    public int opportunityPassive() {
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每3级升一级
        if (characterLevel % 3 == 0) {
            return true;
        }
        return false;
    }

    @Override
    public int defaultHarm() {
        return 50;
    }

}
